package com.welink.web.resource;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by daniel on 15-3-16.
 */
@Controller
public class Index {
    @RequestMapping(value = "/index.htm")
    public String userStaticLogin(HttpServletRequest request,
                                        HttpServletResponse resp) throws Exception {
        org.apache.shiro.subject.Subject currentUser = SecurityUtils.getSubject();
        long id = -1;
        String name = request.getParameter("name");
        Session session = currentUser.getSession();
        if (null!=session.getAttribute("ud")){
            id  = (long)session.getAttribute("ud");
        }
        session.setAttribute("ud",199l);
        Cookie cookie = new Cookie("XDJ_JESSIONID", session.getId().toString());
        cookie.setMaxAge(19999);
        cookie.setPath("/");
        resp.addCookie(cookie);
        return "index";
    }
}
